<template>
  <div>
    <v-touch v-on:swipeleft="swiperleft" v-on:swiperight="swiperright">
      <div class="swiper-container3 con-banner">
        <div class="swiper-wrapper con-wrapper">
          <div class="swiper-slide bg-blue"><slot name="s0"></slot></div>
          <div class="swiper-slide bg1"><slot name="s1"></slot></div>
          <div class="swiper-slide bg2"><slot name="s2"></slot></div>
          <div class="swiper-slide bg3"><slot name="s3"></slot></div>
          <div class="swiper-slide bg4"><slot name="s4"></slot></div>
          <div class="swiper-slide bg1"><slot name="s5"></slot></div>
          <div class="swiper-slide bg2"><slot name="s6"></slot></div>
          <div class="swiper-slide bg3"><slot name="s7"></slot></div>
          <div class="swiper-slide bg4"><slot name="s8"></slot></div>
        </div>
      </div>
    </v-touch>
  </div>
</template>
<script>
import Swiper from "../assets/swiper/dist/js/swiper.min.js";
export default {
  name: "demoZi",
  //   接收
  props: ["send"],
  data() {
    return {
      x: 0,
      ifLeft: true,
      ifRight: true,
    };
  },
  created() {
    // 判断页面是否重新加载
    console.log("重新加载啦");
  },
  methods: {
    swiperleft() {
      console.log("左划");
      this.x++;
      this.$emit("child-click", this.x);
      console.log("当前x的值===>", this.x);
    },
    swiperright() {
      console.log("右划");
      this.x--;
      this.$emit("child-click", this.x);
      console.log("当前x的值===>", this.x);
    },
  },
  mounted() {
    console.log("父给子的值==>", this.send);
    this.x = this.send;
    var mySwiper3 = new Swiper(".swiper-container3", {
      // autoplay: 1000, //可选选项，自动滑动
      initialSlide: this.send,
    });
  },
};
</script>

<style lang="scss" scoped>
.con-banner {
  overflow: auto;
  position: relative;
  top: 46px;
  left: 94px;
  .con-wrapper {
    //   一定要给这个值，tmd搞了一早上草啊
    width: 282px !important;
    display: flex;
    .swiper-slide {
      flex-shrink: 0;
      width: 282px !important;
      min-height: 200px;
    }
  }
}
.swiper-slide-active {
  width: 282px !important;
}
.bg-blue {
  // color: skyblue;
  background-color: rgb(207, 102, 102);
}
.bg1 {
  background: rgb(251, 189, 189);
}
.bg2 {
  background: rgb(52, 161, 128);
}
.bg3 {
  background: rgb(118, 98, 207);
}
.bg4 {
  background: rgb(188, 212, 131);
}
</style>